<template>
  <div>
    <el-button type="primary">项目金额: {{sum}}元</el-button>
    <el-button type="primary" @click="pay">检验收费结算</el-button>
    <el-table ref="wytable" style="margin-top: 20px;" :data="props.tableData" @selection-change="selectionChange">
      <el-table-column type="selection"></el-table-column>
      <el-table-column show-overflow-tooltip label="项目名称" prop="medicalTechnology.techName"></el-table-column>
      <el-table-column label="单价" width="120px" prop="medicalTechnology.techPrice"></el-table-column>
      <el-table-column label="类型" width="80px" prop="medicalTechnology.techType"></el-table-column>
      <el-table-column label="规格" width="120px" prop="medicalTechnology.techFormat"></el-table-column>
      <el-table-column label="开立时间" width="150px" prop="creationTime"></el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { post } from '@/util/axios'
import { ref } from 'vue'
import {ElMessage} from "element-plus";
const props = defineProps(['tableData'])
const wytable = ref()
const sum = ref(0)
function selectionChange(newSelection) {
  sum.value = 0
  for (const i in newSelection) {
    sum.value += newSelection[i].medicalTechnology.techPrice
  }
}
function pay () {
  const checkRequestIds = []
  const rows = wytable.value.getSelectionRows()
  for (const i in rows) {
    checkRequestIds.push(rows[i].id)
  }
  post('/inspectionRequest/updateState', { ids: checkRequestIds }, content => {
    window.location.href = window.location.href
    ElMessage.error('支付成功')
  })
}
</script>

<style scoped lang="scss">
</style>
